/**
 * 
 */
package tests.board;

import java.util.ArrayList;

import junit.framework.TestCase;

import org.junit.Test;

import root.JChess;
import root.board.EmptyPlaceException;
import root.board.Piece;
import root.board.moviment.Moviment;
import root.board.moviment.Position;

/**
 * @author Calebe
 * 
 */
public class GetEnabledMovimentsPawn extends TestCase {

	JChess jchess;

	@Test
	public void testEatLeaft() {
		jchess = new JChess();
		jchess.newGame();
		ArrayList<Moviment> moviments = new ArrayList<Moviment>();
		if (jchess.isPiecePresent(new Position(2, 1))) {
			try {
				jchess.move(new Position(4, 1), new Position(4, 5));
				if (jchess.isPiecePresent(new Position(3, 6))) {
					moviments = jchess.getEnabledMoviments(3, 6);
				}
			} catch (EmptyPlaceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		assertEquals(3, moviments.size());

	}

	@Test
	public void testEatRigth() {
		jchess = new JChess();
		jchess.newGame();
		ArrayList<Moviment> moviments = new ArrayList<Moviment>();
		if (jchess.isPiecePresent(new Position(2, 1))) {
			try {
				jchess.move(new Position(2, 1), new Position(2, 5));
				if (jchess.isPiecePresent(new Position(3, 6))) {
					moviments = jchess.getEnabledMoviments(3, 6);
				}
			} catch (EmptyPlaceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		assertEquals(3, moviments.size());

	}

	@Test
	public void testFirstMovimentBlockedFirstPosition() {
		jchess = new JChess();
		jchess.newGame();
		Piece pawn = null;
		ArrayList<Moviment> moviments = null;
		try {
			pawn = jchess.getPieceOn(2, 1);
			if (pawn != null)
				jchess.move(new Position(2, 1), new Position(3, 2));

			moviments = jchess.getEnabledMoviments(3, 1);
		} catch (EmptyPlaceException e) {
			e.printStackTrace();
		}
		assertEquals(0, moviments.size());

	}

	@Test
	public void testFirstMovimentBlockedSecondPosition() {
		jchess = new JChess();
		jchess.newGame();
		Piece pawn = null;
		ArrayList<Moviment> moviments = null;
		try {
			pawn = jchess.getPieceOn(2, 1);
			if (pawn != null)
				jchess.move(new Position(2, 1), new Position(3, 3));
			moviments = jchess.getEnabledMoviments(3, 1);
		} catch (EmptyPlaceException e) {
			e.printStackTrace();
		}
		assertEquals(1, moviments.size());

	}

	@Test
	public void testFirstMovimentFree() {
		jchess = new JChess();
		jchess.newGame();
		ArrayList<Moviment> moviments = new ArrayList<Moviment>();
		try {
			moviments = jchess.getEnabledMoviments(2, 1);
		} catch (EmptyPlaceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (Moviment moviment : moviments) {
			System.out.println(moviment);
		}
		assertEquals(2, moviments.size());

	}

	@Test
	public void testFirstMovimentFreeSouth() {
		jchess = new JChess();
		jchess.newGame();
		ArrayList<Moviment> moviments = new ArrayList<Moviment>();
		try {
			moviments = jchess.getEnabledMoviments(2, 6);
		} catch (EmptyPlaceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		for (Moviment moviment : moviments) {
			System.out.println(moviment);
		}
		assertEquals(2, moviments.size());
	}
}
